using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ThridGroup.ERP.ProductionSystem;

namespace ThridGroup.ERP.EntityFrameworkCore.Configurations
{
    public class WorkshopConfiguration : IEntityTypeConfiguration<Workshop>
    {
        public void Configure(EntityTypeBuilder<Workshop> builder)
        {
            builder.ToTable("Workshops");

            builder.HasKey(x => x.Id);
            
            // 主键
            builder.Property(x => x.Id)
                .HasColumnName("Id")
                .ValueGeneratedOnAdd()
                .IsRequired();

            // 车间编码
            builder.Property(x => x.Code)
                .IsRequired()
                .HasMaxLength(50)
                .HasColumnName("WorkshopCode");

            // 车间名称
            builder.Property(x => x.Name)
                .IsRequired()
                .HasMaxLength(100)
                .HasColumnName("WorkshopName");

            // 车间描述
            builder.Property(x => x.Description)
                .HasMaxLength(500)
                .HasColumnName("Context");

            // 车间规模
            builder.Property(x => x.WorkshopSize)
                .HasMaxLength(50)
                .HasColumnName("WorkshopSize");

            // 车间负责人
            builder.Property(x => x.WorkshopPerson)
                .HasMaxLength(50)
                .HasColumnName("WorkshopPerson");

            // 是否启用
            builder.Property(x => x.IsEnable)
                .IsRequired()
                .HasColumnName("IsEnable");
                
            // 忽略创建时间字段，因为数据库表中不存在该列
            builder.Ignore(x => x.CreateTime);

            // 以下字段在数据库中不存在，忽略映射
            builder.Ignore(x => x.ParentId);
            builder.Ignore(x => x.ParentName);
            builder.Ignore(x => x.Index);
            builder.Ignore(x => x.IsDeleted);
            builder.Ignore(x => x.Children);
        }
    }
} 